package com.cosmoplat.xikai.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cosmoplat.xikai.business.domain.BaseAlarmRecord;
import com.cosmoplat.xikai.business.domain.DeviceFault;
import com.cosmoplat.xikai.business.domain.DeviceLog;
import com.cosmoplat.xikai.business.domain.EnergyManagement;
import com.cosmoplat.xikai.business.domain.dto.scada.DeviceFaultDto;
import com.cosmoplat.xikai.business.mapper.DeviceLogMapper;
import com.cosmoplat.xikai.business.service.DeviceLogService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName DeviceLogServicImpl
 * @Description 设备日志服务实现类
 * @Author wdf
 * @Date 2025/1/13
 */
@Service
public class DeviceLogServiceImpl extends ServiceImpl<DeviceLogMapper, DeviceLog> implements DeviceLogService {
    @Override
    public ArrayList<DeviceFault> queryForPage(DeviceFaultDto deviceFaultDto) {
        return this.baseMapper.queryForPage(deviceFaultDto);
    }

    @Override
    public ArrayList<EnergyManagement> queryEnergyManagementForPage(DeviceFaultDto deviceFaultDto) {
        return this.baseMapper.queryEnergyManagementForPage(deviceFaultDto);
    }

    @Override
    public DeviceLog getDeviceLogByThingModelId(Long thingModelId) {
        return this.baseMapper.selectByThingModelId(thingModelId);
    }

    @Override
    public DeviceLog getLastByThingModelId(Long thingModelId) {
        QueryWrapper<DeviceLog> queryWrapper = new QueryWrapper<>();
        QueryWrapper<DeviceLog> wrapper = new QueryWrapper<>();
        wrapper.select(" top  1  * ")
                .orderByAsc("id");
        List<DeviceLog> list = this.list(wrapper);
        if (CollectionUtils.isNotEmpty(list)) {
            return list.get(0);
        }
        return null;
    }
}
